﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href="<?=base_url()?>css/admin-bar.css" type="text/css" rel="stylesheet" />
<link href="<?=base_url()?>css/admin-menu.css" type="text/css" rel="stylesheet" />
<link href="<?=base_url()?>css/admin.css" type="text/css" rel="stylesheet" />
<link href="<?=base_url()?>css/demo_page.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="<?=base_url()?>css/demo_table_jui.css" />
<link href="<?=base_url()?>css/jquery.bubblepopup.v2.3.1.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="<?=base_url()?>css/smoothness/jquery-ui-1.8.16.custom.css" />
<style>
	span{ font-family:Georgia, "Times New Roman", Times, serif; color:#FF0000; font-size:18px}
	a{ font-family:"Times New Roman", Times, serif; font-size:14px; color:#993333; text-decoration:none;}
	#wp-post-comment{ width:45%; float:left; margin-right:10px;}
	#wp-draft-views{ width:45%; float:left; margin-left:10px; }
	#flot-views{ width:100%; height:200px;}
	.cataName{width:98%; font-size:18px; height:30px; font-family:"Times New Roman", Times, serif; margin: 5px}
	.write{ width:98%; margin:5px;}
	#xoa{ margin-left:30px; margin-right: 150px;}
	#chuyenmuc{ width:98%; margin:5px; font-size:16px; height:30px;}
	.thongbao{color:red; font-size:16px; font-weight:bold}
</style>
<!--[if lte IE 8]><script type="text/javascript" src="<?=base_url()?>js/excanvas.min.js"></script><![endif]-->
<script type="text/javascript" src="<?=base_url()?>js/jquery.min.js"></script>
<script type="text/javascript" src="<?=base_url()?>js/jquery.dataTables.min.js"></script>
<script src="<?=base_url()?>js/jquery.bubblepopup.v2.3.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$('#example').dataTable( {
			"aaSorting":[[4,'desc']],
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"aoColumns": [{"bSearchable": false},
						  {"bSearchable": false, "bSortable": false},
			              null,
						  {"bSortable": false},
						  {"bSortable": false},
			              {"bSearchable": false},
			              null,
			              {"bSearchable": false, "bSortable": false}]
		});
		
		$('.editBtn').hover(function(){
			$(this).attr('src','<?=base_url()?>images/edit_hover.png');
		}, function(){
			$(this).attr('src','<?=base_url()?>images/edit.png');
		});
		$('.delBtn').hover(function(){
			$(this).attr('src','<?=base_url()?>images/trash_hover.png');
		}, function(){
			$(this).attr('src','<?=base_url()?>images/trash.png');
		});
		$('.staBtn').hover(function(){
			$(this).attr('src','<?=base_url()?>images/accept-icon_2.png');
		}, function(){
			$(this).attr('src','<?=base_url()?>images/accept-icon_1.png');
		});

		$('#loaicha').change(function(){
			
			var loaicha = ($(this).attr('value'));
			//alert(loaicha);
			$.post("<?=base_url()?>index.php/qlsp_controller/getLoaiSPCon",{loaicha:loaicha},function(data){
				//alert(loaicha);
				$('#loaicon').html(data);
			});
			$.post("<?=base_url()?>index.php/qlsp_controller/getSanPham_ajax",{loaicha:loaicha},function(data){
				//alert(data);
				$('#noi_dung').html(data);
			});
		});
		
		$('.trangthai').click(function(){
			var masp = ($(this).attr('lang'));
			//alert(masp);
			var conf = confirm("Sản phẩm đã hết hàng?");
			if(conf == true){
				$.post("<?=base_url()?>index.php/qlsp_controller/hethang",{masp:masp},function(data){
					//alert(masp);
					$('#'+masp).html(data);
					//alert(masp);
					});
			}else{
				return false;
			}
		});
	})
</script>
<script type="text/javascript">

	function show_confirm(){
		var conf = confirm("Bạn thật sự muốn xóa?");
		if(conf == true){
			return true;
		}else{
			return false;
		}
	}
	function show_confirm_status(){
		var conf = confirm("Sản phẩm đã hết hàng?");
		if(conf == true){
			return true;
		}else{
			return false;
		}
	}
	
</script>

</head>
<body>
<?=$bar?>
<div id="main-content">
<?=$sidemenu?>
<script type="text/javascript">
	$('#sidemenu #home').addClass('current-top');
</script>
<div id="content">
	<div id="content-head">
    	<h1>Quản lý sản phẩm</h1>
<?php /*?>        <?php 
			echo $_SESSION['tenanh'];
		?><?php */?>
    </div>
    <div id="content-body">
		<form name="post_form" action="" method="get">
			<span style="font-style:italic">Chào mừng <b style="color:red"><?=$_SESSION['tentaikhoan'];?></b></span>
			<hr>
			<h2><a href="<?=base_url()?>index.php/qlsp_controller/dangsanpham" style="background-color:#CCCCCC; font-size:14px; font-style:normal; text-decoration:none" class="content-submit">Đăng sản phẩm</a></h2>
			Xem chuyên mục:&nbsp;<select name="loaicha" id="loaicha">
				<option value='1'>------Tất cả------</option>               
                <?php
					for($i=1; $i<count($loaispcha); $i++){
						echo "<option value=".$loaispcha[$i]['MaLoaiSP'].">".$loaispcha[$i]['TenLoaiSP']."</option>";
					}
				?>
                </select>
                &nbsp;&nbsp;
             Loại sản phẩm: &nbsp;
             <span  name="loaicon" id="loaicon">
             <select>
				<option value='1'>-----Tất cả------</option>               
			</select>
			</span>
			<hr>
         	<div id="noi_dung">
			<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
				<thead>
					<tr>
						<th width="8%">Số thứ tự</th>
						<th>Ảnh sản phẩm</th>
						<th>Tên sản phẩm</th>
                        <th>Mô tả sản phẩm</th>
						<th>Ngày đăng</th>
						<th>Loại sản phẩm</th>
						<th>Giá bán</th>
						<th>Thao tác</th>
					</tr>
				</thead>
				<tbody id="noidung_ajax">
					<?php
						for($i=0; $i<count($sanpham); $i++){
							$noi_dung =  $sanpham[$i]['MoTa'];
							$link_anh = base_url()."images/product/".$sanpham[$i]['AnhSanPham'];
							if(strlen($noi_dung)>=80){
								$tom_tat = substr($noi_dung, 0, 80);
								$index = strrpos($tom_tat, " " );
								$tom_tat = substr($tom_tat, 0, $index+1)."...";
							}else{
								$tom_tat = $noi_dung;
							}
							$link_sua = base_url()."index.php/qlsp_controller/suasanpham/".$sanpham[$i]['MaSanPham'];
							$link_xoa = base_url()."index.php/qlsp_controller/xoasanpham/".$sanpham[$i]['MaSanPham'];
														
							echo"<tr class='gradeU'>";
								echo"<td align='center'>".($i+1)."</td>";
								echo"<td align='center'><a href='$link_sua'><img src=".$link_anh." height='100' width='100'/></a></td>";
								echo"<td><b>".$sanpham[$i]['TenSanPham']."</b></td>";
								echo"<td><p title='$noi_dung'>".$tom_tat."</p></td>";
								echo"<td align='center'>".$sanpham[$i]['NgayDang']."</td>";
								echo"<td align='center'>".$sanpham[$i]['TenLoaiSP']."</td>";
								echo"<td class='center' width='100'>".$sanpham[$i]['GiaBan']." VNĐ</td>";
								if($sanpham[$i]['TrangThai'] == 1){
									echo"<td class='center'><a href='$link_sua' title='Sửa sản phẩm'><img class='editBtn' src='".base_url()."images/edit.png' height='32' width='32' ></a><a href='$link_xoa' title='Xóa sản phẩm' onclick='return show_confirm();'><img class='delBtn' src='".base_url()."images/trash.png' height='32' width='32' ></a><span id='".$sanpham[$i]['MaSanPham']."'><a class='trangthai' lang='".$sanpham[$i]['MaSanPham']."'><img  title='Hết hàng' class='staBtn' src='".base_url()."images/accept-icon_1.png' height='32' width='32' ></a></span></td>";
								}else{
									echo"<td class='center'><a href='$link_sua' title='Sửa sản phẩm'><img class='editBtn' src='".base_url()."images/edit.png' height='32' width='32' ></a><a href='$link_xoa' title='Xóa sản phẩm' onclick='return show_confirm();'><img class='delBtn' src='".base_url()."images/trash.png' height='32' width='32' ></a><span style='font-size:16px'>Hết hàng!</span></td>";
								}
							echo"</tr>";
						}
					?>
				</tbody>
			</table>
            </div>		
		</form>
    </div>
	<span style="font-size:16px"
</div>
</div>
</body>
</html>